Description:
The C# compiler does not produce an error or warning when not all of the enumeration constants are handled in a switch statement and no default branch is provided. Although in many situations it is desired behavior, it can also be programmer error; therefore, ECNHS produces error messages in these cases. To eliminate this message and to clarify your code, add the explicit default branch.
Incorrect:
enum Colors {
Red,
Green,
Blue
};
int GetColor(Colors c) {
switch (c) {
case Colors.Red:
return 0xFF0000;
case Colors.Green:
return 0x00FF00;
}
return 0;
}
Correct:
enum Colors {
Red,
Green,
Blue
};
int GetColor(Colors c) {
switch (c) {
case Colors.Red:
return 0xFF0000;
case Colors.Green:
return 0x00FF00;
case Colors.Blue:
return 0x0000FF;
}
return 0;
}